package Square;
import java.math.BigDecimal;

import Border.BorderType;
import Border.Direction;



public class Rock extends Square {

	/**
	 * Creates a new rock
	 * 
	 * @effect	This Rock is initialized as a new Square with the default constructor
	 * 			| super()
	 * @post 	All borders are set to BorderType.WALL
	 * 			| for each direction in Border.Direction
	 *			|	this.getBorderAt(direction).getBorderType == Border.BorderType.WALL;
	 *
	 */
	public Rock()
	{
		super();
		for(Direction direction : Direction.values())
			this.getBorderAt(direction).setBorderType(BorderType.WALL);
	}
	
	/**
	 * Returns the temperature of this square
	 * 
	 * @return	The temperature of this square (which equals the average temperature of its surrounding squares)
	 * 			| totalTemperature = 0
	 *	 		| amountOfSquares = 0
	 * 			| for each direction in Border.Direction
	 *			|	otherSquare = this.getBorderAt(direction).getOtherSquare(this);
	 *			|	if(otherSquare != null && otherSquare.getClass() != Rock.class)
	 *			|		total =+ otherSquare.getTemperature();
	 *			|		amountOfSquares++;
	 *			|
	 *			| result == totalTemperature / amountOfSquares; 
	 * @note	Surrounding rocks will be ignored in the calculation
	 */
	@Override
	public double getTemperature() {
		double totalTemperature = 0;
		int amountOfSquares = 0;
		for(Direction direction : Direction.values())
		{
			Square otherSquare = this.getBorderAt(direction).getOtherSquare(this);
			if(otherSquare != null && otherSquare.getClass() != Rock.class)
			{
				totalTemperature =+ otherSquare.getTemperature();
				amountOfSquares++;
			}

		}
		return (double)totalTemperature / amountOfSquares;
	}

	/**
	 * Returns the humidity of this rock
	 * 
	 * @return	The humidity of this rock (which will always be zero)
	 * 			| result == 0
	 */
	@Override
	public BigDecimal getHumidity() {
		return new BigDecimal(0);
	}

	/**
	 * @param	type
	 * 			The bordertype that the border will be set to
	 * @param	direction
	 * 			The direction of the border that will be modified
	 * @return	True if and only if the type is BorderType.WALL
	 * 			| result == (type == BorderType.WALL)
	 */
	@Override
	public boolean canHaveAsBorderType(BorderType type, Direction direction) {
		return (type == BorderType.WALL);
	}
	
}
